home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 October / Macworld (1998-10).dmg / Shareware World / Info / For Developers / MacZoop 1.8.4 / More Classes / Window Classes / xDEFJump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-11  |  1.8 KB  |  57 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *        xDEFJump.c            - allows embedded xDEFs to be called internally
  4. *
  5. *
  6. *        13/7/94  Graham Cox
  7. *
  8. *
  9. *************************************************************************************************/
  10.  
  11. #include    "xDEFjump.h"
  12.  
  13.  
  14.  
  15. Handle    GetUniversalFunctionHandle(ProcPtr functionAddress, ProcInfoType pInfo)
  16. {
  17.     Handle                pHNullProc = NULL;
  18.     ISAType                isa;
  19.     UniversalProcPtr     axDEFUPP;
  20.     
  21.     isa = GetCurrentISA();
  22.     
  23.     if (isa == kPowerPCISA)
  24.     {
  25.        pHNullProc = NewHandle(sizeof(RoutineDescriptor));
  26.        axDEFUPP = NewRoutineDescriptor(functionAddress,pInfo,isa);
  27.        BlockMoveData(axDEFUPP, *pHNullProc, sizeof(RoutineDescriptor));
  28.        DisposeRoutineDescriptor(axDEFUPP);
  29.     }
  30.     else
  31.     {
  32.        pHNullProc = NewHandle(sizeof(JmpInstructionTemplate));
  33.        PatchJmpInstruction(*pHNullProc, (void*)functionAddress);
  34.     }
  35.     return(pHNullProc);
  36. }
  37.  
  38.  
  39. void PatchJmpInstruction(void* patchAddress, void* jumpAddress)
  40. {
  41.    JmpInstructionTemplate* aJmpInstructionPtr;
  42.    
  43.    aJmpInstructionPtr = (JmpInstructionTemplate *) patchAddress;
  44.    aJmpInstructionPtr->Jmp = 0x4EF9;
  45.    aJmpInstructionPtr->Routine = jumpAddress;
  46. }
  47.  
  48. /* Thanks to Apple DTS for the method */
  49.  
  50. /* This new version of Sneaky Jump supplies a new function- GetUniversalFunctionHandle().
  51.     It takes two parameters- the function address and the parameter info. It will compile under the
  52.     new universal headers for the PowerPC. Your routine needs to supply the appropriate constant
  53.     for the type of xDEF that is being called- unfortunately this is less universal than it used
  54.     to be in this respect. The type of jump is resolved at run time- on a 680x0 mac, the old style
  55.     fake jump is created instead. It is the caller's responsibility to dispose of the handle when
  56.     done with it.
  57. */